package com.laolei.core.utils;

import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

import com.laolei.core.Context;
import com.laolei.core.init.LoginInitalize;
import com.laolei.core.model.SysUser;

@Component
@ComponentScan
public class ContextUtils {
	static LoginInitalize loginInitalize;

	@Autowired(required = false)
	void set(LoginInitalize loginInitalize) {
		ContextUtils.loginInitalize = loginInitalize;
	}

	public static Optional<SysUser> initLoginInfo() {
		Optional<SysUser> user;
		if (loginInitalize != null)
			user = Optional.of(loginInitalize.findLoginUser());
		else
			user = SysUser.empty;
		Context.setUser(user);
		return user;
	}
}
